package com.sanqi.weixin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sanqi.common.annotation.Log;
import com.sanqi.common.core.controller.BaseController;
import com.sanqi.common.core.domain.AjaxResult;
import com.sanqi.common.enums.BusinessType;
import com.sanqi.weixin.domain.WxApp;
import com.sanqi.weixin.service.IWxAppService;
import com.sanqi.common.utils.poi.ExcelUtil;
import com.sanqi.common.core.page.TableDataInfo;

/**
 * 微信应用Controller
 * 
 * @author duany
 * @date 2025-09-24
 */
@RestController
@RequestMapping("/weixin/app")
public class WxAppController extends BaseController
{
    @Autowired
    private IWxAppService wxAppService;

    /**
     * 查询微信应用列表
     */
    @PreAuthorize("@ss.hasPermi('weixin:app:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxApp wxApp)
    {
        startPage();
        List<WxApp> list = wxAppService.selectWxAppList(wxApp);
        return getDataTable(list);
    }

    /**
     * 导出微信应用列表
     */
    @PreAuthorize("@ss.hasPermi('weixin:app:export')")
    @Log(title = "微信应用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxApp wxApp)
    {
        List<WxApp> list = wxAppService.selectWxAppList(wxApp);
        ExcelUtil<WxApp> util = new ExcelUtil<WxApp>(WxApp.class);
        util.exportExcel(response, list, "微信应用数据");
    }

    /**
     * 获取微信应用详细信息
     */
    @PreAuthorize("@ss.hasPermi('weixin:app:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(wxAppService.selectWxAppById(id));
    }

    /**
     * 新增微信应用
     */
    @PreAuthorize("@ss.hasPermi('weixin:app:add')")
    @Log(title = "微信应用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxApp wxApp)
    {
        return toAjax(wxAppService.insertWxApp(wxApp));
    }

    /**
     * 修改微信应用
     */
    @PreAuthorize("@ss.hasPermi('weixin:app:edit')")
    @Log(title = "微信应用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxApp wxApp)
    {
        return toAjax(wxAppService.updateWxApp(wxApp));
    }

    /**
     * 删除微信应用
     */
    @PreAuthorize("@ss.hasPermi('weixin:app:remove')")
    @Log(title = "微信应用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(wxAppService.deleteWxAppByIds(ids));
    }
}
